package com.infodms.dms.dao.claim.oldPart;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.ClaimOldPartRemainStoreListBean;
import com.infodms.dms.common.Utility;
import com.infodms.dms.dao.common.BaseDao;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;

@SuppressWarnings("unchecked")
public class ClaimOldPartStorageManagerDao extends BaseDao {
	public static Logger logger = Logger.getLogger(ClaimOldPartStorageManagerDao.class);

	private static final ClaimOldPartStorageManagerDao dao = null;

	public static final ClaimOldPartStorageManagerDao getInstance() {
		if (dao == null)
			return new ClaimOldPartStorageManagerDao();
		return dao;
	}
	/**
	 * Function：查询库存信息
	 * @param  ：	
	 * @return:		@param params
	 * @return:		@param curPage
	 * @return:		@param pageSize
	 * @return:		@return 
	 * @throw：	
	 * LastUpdate：	2010-6-18
	 */
	public PageResult<ClaimOldPartRemainStoreListBean> getCurStoreList(Map params,int curPage, int pageSize){
		String company_id=ClaimTools.dealParamStr(params.get("company_id"));
		String supply_name=ClaimTools.dealParamStr(params.get("supply_name"));//查询条件--供应商简称
		String part_code=ClaimTools.dealParamStr(params.get("part_code"));//查询条件--配件代码
		String part_name=ClaimTools.dealParamStr(params.get("part_name"));//查询条件--配件名称
		String yieldly=ClaimTools.dealParamStr(params.get("yieldly"));//查询条件--产地
		String yieldlys=ClaimTools.dealParamStr(params.get("yieldlys"));//用户拥有产地
		
		StringBuffer sqlStr=new StringBuffer();
		sqlStr.append("select tps.short_name supply_name,tawps.part_code,tppb.part_name,\n" );
		sqlStr.append("tawps.return_amount-tawps.out_amount remain_amount,tawps.yieldly\n" );
		sqlStr.append("from TT_AS_WR_PART_STOCK tawps,\n" );
		sqlStr.append("TM_PT_SUPPLIER tps,\n" );
		sqlStr.append("Tm_Pt_Part_Base tppb\n" );
		sqlStr.append("where tawps.producer_id=tps.supplier_id(+)\n" );
		sqlStr.append("and tawps.part_id=tppb.part_id(+)\n" );
		sqlStr.append("and tawps.oem_company_id="+company_id+"\n" );
		//sqlStr.append("and tppb.oem_company_id="+company_id+"\n" );
		sqlStr.append("and tawps.yieldly in ("+yieldlys+")\n" );
		if(Utility.testString(supply_name)){
			sqlStr.append("and tps.short_name like '%"+supply_name.replaceAll("'", "\''")+"%'\n" );
		}
		if(Utility.testString(part_code)){
			sqlStr.append("and tawps.part_code like '%"+part_code.replaceAll("'", "\''")+"%'\n" );
		}
		if(Utility.testString(part_name)){
			sqlStr.append("and tppb.part_name like'%"+part_name.replaceAll("'", "\''")+"%'\n" );
		}
		if(Utility.testString(yieldly))
			sqlStr.append("and tawps.yieldly ='"+yieldly+"'\n" );
		
		sqlStr.append("and (tawps.return_amount-tawps.out_amount)>0\n" );
		sqlStr.append("order by tawps.id desc");
		PageResult<ClaimOldPartRemainStoreListBean> pr=pageQuery(ClaimOldPartRemainStoreListBean.class, sqlStr.toString(), null, pageSize, curPage);
		return pr;
    }
	public List<Map<String, Object>> getCurStoreTotalExportList(Map params){
		String company_id=ClaimTools.dealParamStr(params.get("company_id"));
		String supply_name=ClaimTools.dealParamStr(params.get("supply_name"));//查询条件--供应商简称
		String part_code=ClaimTools.dealParamStr(params.get("part_code"));//查询条件--配件代码
		String part_name=ClaimTools.dealParamStr(params.get("part_name"));//查询条件--配件名称
		
		StringBuffer sqlStr=new StringBuffer();
		sqlStr.append("select tps.short_name supply_name,tawps.part_code,tppb.part_name,\n" );
		sqlStr.append("tawps.return_amount-tawps.out_amount remain_amount\n" );
		sqlStr.append("from TT_AS_WR_PART_STOCK tawps,\n" );
		sqlStr.append("TM_PT_SUPPLIER tps,\n" );
		sqlStr.append("Tm_Pt_Part_Base tppb\n" );
		sqlStr.append("where tawps.producer_id=tps.supplier_id(+)\n" );
		sqlStr.append("and tawps.part_id=tppb.part_id(+)\n" );
		sqlStr.append("and tawps.oem_company_id="+company_id+"\n" );
		sqlStr.append("and tppb.oem_company_id="+company_id+"\n" );
		if(!"".equals(supply_name)){
			sqlStr.append("and tps.short_name like '%"+supply_name.replaceAll("'", "\''")+"%'\n" );
		}
		if(!"".equals(part_code)){
			sqlStr.append("and tawps.part_code like '%"+part_code.replaceAll("'", "\''")+"%'\n" );
		}
		if(!"".equals(part_name)){
			sqlStr.append("and tppb.part_name like '%"+part_name.replaceAll("'", "\''")+"%'\n" );
		}
		sqlStr.append("and (tawps.return_amount-tawps.out_amount)>0\n" );
		sqlStr.append("order by tawps.id desc");
		List<Map<String, Object>> list = pageQuery(sqlStr.toString(), null,"com.infodms.dms.dao.claim.oldPart.ClaimOldPartStorageManagerDao.getDealerSalesOrderTotalExportList");
        return list;
	}
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		return null;
	}
}
